package base.arrays;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.function.Consumer;

public class 泛型方法 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        ListUtil.addAll(list,1,2,3,4,5,6,7,8,9,10);
        //迭代器遍历
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()){
            Integer num = it.next();
            System.out.print(num+" ");
        }
    }
}

class ListUtil{
    private ListUtil(){};
    //定义一个addAll方法，用来添加多个元素到集合中;
    public static <E> void addAll(ArrayList<E> list, E ...e){
        for (E element : e){
            list.add(element);
        }
    }
}

